from re import A
from sqladmin import ModelView
from model import blog


class BlogCategoryAdmin(ModelView, model=blog.BlogCategory):
    name = "博客类型"
    name_plural = "博客类型"
    column_default_sort = [("id", True)]
    column_labels = {"id": "博客类型id", "title": "博客类型标题",
                     "is_deleted": "是否删除", "create_time": "创建时间", "update_time": "更新时间"}
    column_list = [blog.BlogCategory.id, blog.BlogCategory.title]
    column_searchable_list = [blog.BlogCategory.title]


class BlogAdmin(ModelView, model=blog.Blog):
    name = "博客"
    name_plural = "博客"
    edit_template = "sqladmin/custom_edit.html"
    column_default_sort = [("id", True)]
    column_labels = {"id": "博客id", "title": "博客标题", "category": "博客类型", "content": "博客内容",
                     "is_deleted": "是否删除", "create_time": "创建时间", "update_time": "更新时间"}
    column_list = [blog.Blog.id, blog.Blog.title, blog.Blog.category]
    column_searchable_list = [blog.Blog.title]
    column_sortable_list = [blog.Blog.id]
    form_columns = [blog.Blog.title, blog.Blog.category, blog.Blog.content]

    form_widget_args = {
        "content": {
            "class": "rich-text"
        },

    }


